package com.ch.sys.model;

import java.util.HashMap;
import java.util.Map;

import com.ch.fastbuilder.common.GenerationType;
import com.ch.fastbuilder.model.Model;
import com.ch.sys.utils.SHA1;

public class Employee extends Model {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public static String TABLE = "employee";
	public static String ID = "id";
	public static String ACCOUNT = "account";
	public static String PASSWORD = "password";
	public static String NICKNAME = "nickname";
	public static String GENDER = "gender";
	public static String HEAD_URL = "head_url";
	public static String TYPE = "type";
	public static String CREATED = "created";
	
	public Employee() {
		super.setPrimaryKey(ID);
		super.setTableName(TABLE);
		//super.setGenerationType(GenerationType.UUID);
		super.setGenerationType(GenerationType.IDENTITY);
		super.setColumns(ID,ACCOUNT,PASSWORD,NICKNAME,GENDER,HEAD_URL,TYPE,CREATED);
	}
	
	public static Employee getByAccountPwd(String account, String password) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("account", account);
		params.put("password", SHA1.signature(password));
		
		String sql = "account=:account and password=:password";
		Employee employee = Model.Where(sql, params).get(Employee.class);
		
		return employee;
	}
}
